{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ***Introduction to Radar Using Python and MATLAB***\n",
    "## Andy Harrison - Copyright (C) 2019 Artech House\n",
    "<br/>\n",
    "\n",
    "# Apparent Range\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Since a wave transmitted through the atmosphere experiences a refractive index that is a function of altitude, the path length from the transmitter to the target exceeds the geometrical path length, as shown in Figure 2.9. This difference in range is described by the integral\n",
    "\n",
    "$$\n",
    "\\Delta R = \\int \\limits_{A}^{B} (n - 1) \\, dl,\n",
    "$$\n",
    "\n",
    "where $l$ is the length along the path, and $(A, B)$ is the starting and ending points of the path.  This expression is used when the variation of the constitutive parameters along the integration path are known.  A semiempirical method was developed in order to calculate the apparent range when the temperature, atmospheric pressure, and relative humidity are known at ground level.  This method was derived in 1979 using atmospheric radio profiles at 500 meteorological stations over the course of one year.  The expression for the difference in range for this method is\n",
    "\n",
    "$$\n",
    "\\Delta R = \\frac{\\Delta R_V}{\\sin \\theta \\sqrt{(1 + k \\cot^2\\theta)}} + \\delta(\\theta, \\Delta R_V),\n",
    "$$\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Begin by getting the library path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import lib_path"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Set the radar and target location (latitude (deg), longitude (deg), altitude (m))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import array\n",
    "\n",
    "radar_lla = array([34.0,  84.0,  120.0])\n",
    "\n",
    "target_lla = array([34.0, 80.0, 12000.0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Set up the keyword args"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "kwargs = {'radar_lla': radar_lla, 'target_lla': target_lla}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculate the true and apparent ranges using the `apparent_range` routine"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from Libs.wave_propagation import refraction\n",
    "\n",
    "true_range, apparent_range = refraction.apparent_range(**kwargs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Display the true and apparent ranges"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "370.0054\n",
      "370.0776\n"
     ]
    }
   ],
   "source": [
    "print('{:.4f}'.format(true_range/1.e3))\n",
    "\n",
    "print('{:.4f}'.format(apparent_range/1.e3))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
